package com.book.controller;

import com.book.entity.Address;
import com.book.service.AddressService;
import com.book.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * @author yicheng
 */
//所有路径都不可以匿名访问
@RestController
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    /**
     *
     * @param userId 根据id获取他的所有地址
     * @return
     */
    @GetMapping("/list")
    public ResponseResult getAllAddressById(@RequestParam String userId){
        return addressService.getAddressAll(userId);
    }

    /**
     * 接收参数为地址实体类
     * @param address 接收参数为地址实体类
     * @return 返回一个统一格式的返回对象
     */
    @PostMapping("/addAddress")
    public ResponseResult addAddress(@RequestBody Address address){
        return addressService.addAddress(address);
    }

    @GetMapping("/deleteById")
    public ResponseResult delAddress(@RequestParam int id){
        return addressService.deleteAddressById(id);
    }

    @GetMapping("/getOneAddress")
    public ResponseResult getAddressById(@RequestParam int id){
        return addressService.getAddressById(id);
    }

    /**
     * 接收参数为地址实体类
     * @param address 接收参数为地址实体类
     * @return 返回一个统一格式的返回对象
     */
    @PostMapping("/editAddress")
    public ResponseResult editAddress(@RequestBody Address address){
        return addressService.editAddress(address);
    }
}
